package com.xbenben.demoroot.controller;

import com.alibaba.fastjson.JSONObject;
import com.xbenben.demoroot.bean.UserLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/demo")
public class KafkaController {

    @Autowired
    private KafkaTemplate kafkaTemplate;


    @RequestMapping(value = "/kafka", method = RequestMethod.GET)
    public String sendKafka() {
        UserLog userLog = new UserLog();
        userLog.setUsername("jhp").setUserid(1 + "").setState("0");
        System.err.println("发送用户日志数据:" + userLog);
        kafkaTemplate.send("user-log", 111 + "", JSONObject.toJSONString(userLog));
        return "ok";
    }


    private final static Integer CONTENT_MAX_SIZE = 500;

    public static void main(String[] args) {




        String xx = "Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0Process finished with exit code 0";

        System.out.println(xx.length());
        if (xx.length() > CONTENT_MAX_SIZE) {
            System.out.println("长度 过长");
        }

    }

}
